How do you use the ? : (conditional) operator in JavaScript? And where to use this operator?
Conditional operator in JavaScript
260
19-Jul-2021
Updated on 19-Jul-2021
Ethan Karla
20-Jul-2021Basically for one word if else condition we use ternary operator. This is a one-line shorthand for an if-else statement and It's also known as the conditional operator.
Here is an example of code that could be shortened with the conditional operator:
This can be shortened with the ?: like so:
Hope this information has cleared your confusion.
Happy Coding!